#ifndef _QY_THRAED_MANAGER_H
#define _QY_THREAD_MANAGER_H

#include <queue>
#include <list>
#include "Thread.h"
//#include <tr1/boost_shared_ptr.h>

namespace qy
{

class ThreadManager : public Thread
{
public:
    ThreadManager(int conThreadCount);
	virtual ~ThreadManager();

    //The argument should be a smart pointer, such as boost_shared_ptr<Thread>
	void addThread(Thread *pThread);

protected:
    int run();

private:
    int m_conThreadCount;	//maximum count of concurrent threads
	std::list<Thread*> m_workingThreads;
	std::queue<Thread*> m_waitingThreads;
    pthread_mutex_t m_threadsMutex; //mutex for m_threads
	pthread_cond_t m_threadsCond;
};

}
#endif
